﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LotteryVote.Logic.Web;
using LotteryVote.Logic;
using LotteryVote.Utility;

namespace LotteryVote
{
    public partial class SettleUp : CompanyPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        private bool IsClose(int companyId)
        {
            var company = TodayLotteryCompany.Instance.GetTodayCompany().Find(it => it.CompanyId == companyId);
            if (company == null) return false;
            var closeTime = DateTime.Today.Add(company.CloseTime);
            return closeTime < DateTime.Now;
        }
        protected void btn_settle_Click(object sender, EventArgs e)
        {
            Execute(() =>
            {
                int companyId = lv_company.SelectedValue;
                if (IsClose(companyId))
                {
                    SettleResultFacade settleFacade = new SettleResultFacade();
                    settleFacade.Settle(companyId);
                    ShowMessage("Result", GetGlobalResourceObject("Resource", "Success").ToString());
                }
                else
                    ShowMessage("Result", GetGlobalResourceObject("Resource", "NotCloseTime").ToString());
            });
        }

        protected void btn_reSettle_Click(object sender, EventArgs e)
        {
            Execute(() =>
            {
                int companyId = lv_company.SelectedValue;
                if (IsClose(companyId))
                {
                    SettleResultFacade settleFacade = new SettleResultFacade();
                    settleFacade.ReSettle(companyId);
                    ShowMessage("Result", GetGlobalResourceObject("Resource", "Success").ToString());
                }
                else
                    ShowMessage("Result", GetGlobalResourceObject("Resource", "NotCloseTime").ToString());
            });
        }
    }
}